﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using KaiXin001er.Objects;

namespace KaiXin001er.Logic
{
    public partial class FrmSmartAnswer : Form
    {
        private string[] answerList;//一定是5个
        private int currentAnswer = 0;
        private SmartC sc;
        private Image tImage;
        public string AnswerString
        {
            get
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < answerList.Length; i++)
                {
                    sb.Append("," + answerList[i]);
                }
                return sb.ToString();
            }
        }
        public FrmSmartAnswer()
        {
            InitializeComponent();
        }
        public void setData(SmartC c,Image image)
        {
            this.sc = c;
            this.tImage = image;
        }
        private void button2_Click(object sender, EventArgs e)
        {
            answerList = new string[5];
            a1.Text = "";
            a2.Text = "";
            a3.Text = "";
            a4.Text = "";
            a5.Text = "";
            currentAnswer = 0;
        }

        private void FrmSmartAnswer_Load(object sender, EventArgs e)
        {
            button2_Click(null, null);
            this.pictureBox1.Image = this.tImage;
            lf1.Text = this.sc.Faq[0].Name;
            lf2.Text = this.sc.Faq[1].Name;
            lf3.Text = this.sc.Faq[2].Name;
            lf4.Text = this.sc.Faq[3].Name;
            lf5.Text = this.sc.Faq[4].Name;
        }
        private bool addAnswer(int seq)
        {
            if (currentAnswer == 5) return false;
            answerList[currentAnswer] = this.sc.Faq[seq].Id;
            currentAnswer++;
            return true;
        }
        
        private void lf1_Click(object sender, EventArgs e)
        {
            if (a1.Text != "") return;
            if (addAnswer(0))
            {
                a1.Text = currentAnswer.ToString();
            }
        }

        private void lf2_Click(object sender, EventArgs e)
        {
            if (a2.Text != "") return;
            if (addAnswer(1))
            {
                a2.Text = currentAnswer.ToString();
            }
        }

        private void lf3_Click(object sender, EventArgs e)
        {
            if (a3.Text != "") return;
            if (addAnswer(2))
            {
                a3.Text = currentAnswer.ToString();
            }
        }

        private void lf4_Click(object sender, EventArgs e)
        {
            if (a4.Text != "") return;
            if (addAnswer(3))
            {
                a4.Text = currentAnswer.ToString();
            }
        }

        private void lf5_Click(object sender, EventArgs e)
        {
            if (a5.Text != "") return;
            if (addAnswer(4))
            {
                a5.Text = currentAnswer.ToString();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (currentAnswer == 5)
            {
                this.DialogResult = DialogResult.OK;
                this.Dispose();
            }
            else
            {
                this.DialogResult = DialogResult.Cancel;
                this.Dispose();
            }
        }
    }
}
